package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysThesauriWordReference;
import com.ruoyi.system.service.ISysThesauriWordReferenceService;
import com.ruoyi.system.service.ISysThesauriWordRelationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysThesauriWord;
import com.ruoyi.system.service.ISysThesauriWordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 叙词表数据加工Controller
 * 
 * @author ruoyi
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/system/thesauriWord")
public class SysThesauriWordController extends BaseController
{
    @Autowired
    private ISysThesauriWordService sysThesauriWordService;

    @Autowired
    private ISysThesauriWordReferenceService sysThesauriWordReferenceService;

    /**
     * 查询叙词表数据加工列表
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysThesauriWord sysThesauriWord)
    {
        startPage();
        List<SysThesauriWord> list = sysThesauriWordService.selectSysThesauriWordList(sysThesauriWord);
        String queryAssociation = ServletUtils.getParameter("queryAssociation");
        //是否进行关联查询。为加快查询数据要是没有必要查询就不要查询了
        if(!"no".equals(queryAssociation)){
            SysThesauriWordReference sysThesauriWordReference = null;
            for (SysThesauriWord thesauriWord : list) {
                sysThesauriWordReference = new SysThesauriWordReference();
                sysThesauriWordReference.setThesauriWordId(thesauriWord.getId()+"");
                List<SysThesauriWordReference> sysThesauriWordReferences = sysThesauriWordReferenceService.selectSysThesauriWordReferenceList(sysThesauriWordReference);
                thesauriWord.setSysThesauriWordReferenceList(sysThesauriWordReferences);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出叙词表数据加工列表
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:export')")
    @Log(title = "叙词表数据加工", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysThesauriWord sysThesauriWord)
    {
        List<SysThesauriWord> list = sysThesauriWordService.selectSysThesauriWordList(sysThesauriWord);
        ExcelUtil<SysThesauriWord> util = new ExcelUtil<SysThesauriWord>(SysThesauriWord.class);
        return util.exportExcel(list, "叙词表数据加工数据");
    }

    /**
     * 获取叙词表数据加工详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysThesauriWordService.selectSysThesauriWordById(id));
    }

    /**
     * 新增叙词表数据加工
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:add')")
    @Log(title = "叙词表数据加工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysThesauriWord sysThesauriWord)
    {
        return toAjax(sysThesauriWordService.insertSysThesauriWord(sysThesauriWord));
    }

    /**
     * 修改叙词表数据加工
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:edit')")
    @Log(title = "叙词表数据加工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysThesauriWord sysThesauriWord)
    {
        return toAjax(sysThesauriWordService.updateSysThesauriWord(sysThesauriWord));
    }

    /**
     * 删除叙词表数据加工
     */
    @PreAuthorize("@ss.hasPermi('system:thesauriWord:remove')")
    @Log(title = "叙词表数据加工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysThesauriWordService.deleteSysThesauriWordByIds(ids));
    }
}
